#include <iostream>
#include <string.h>
using namespace std;

class student
{
public:
    int *score; // 动态分配和指针要深
    char name[128];
    student()
    {
        score = new int(100);
        cout << "构造函数被调用" << endl;
    }
    // 自定义的拷贝构造函数会覆盖掉默认拷贝构造函数
    student(const student &stu) // 拷贝构造函数的形参
    {
        cout << "拷贝构造函数被调用" << endl;
        strcpy(this->name, stu.name);
        this->score = new int(*stu.score);
    }
    student &operator=(const student &stu)
    {
        cout << "这是拷贝赋值运算符" << endl;
        strcpy(name, stu.name);
        score = new int(*stu.score);
    }
    void printSocre()
    {
        cout << "his score is:" << score << endl;
    }
};
int main(int argc, char const *argv[])
{
    student stu1;
    strcpy(stu1.name, "王星星");
    cout << "stu1.name=" << stu1.name << "  stu1.score=" << *stu1.score << endl;
    student stu2 = stu1; // 拷贝构造函数(默认或者用户自定义)
    cout << "stu2.name=" << stu2.name << "  stu2.score=" << *stu2.score << endl;
    student stu3;
    stu3 = stu1;
    cout << "stu3.name=" << stu3.name << "  stu3.score=" << *stu3.score << endl;
    return 0;
}
